package com.surenpi.jenkins.client.plugin;

import com.surenpi.jenkins.client.BaseManager;
import java.io.IOException;
import java.util.List;

public class Plugins extends BaseManager {
   public PluginManager getPluginManager() throws IOException {
      return (PluginManager)this.getClient().get("pluginManager/?depth=2", PluginManager.class);
   }

   public boolean pluginsExists(String[] pluginArray) throws IOException {
      if (pluginArray == null) {
         return true;
      } else {
         PluginManager pluginMgr = this.getPluginManager();
         List<Plugin> pluginList = pluginMgr.getPlugins();
         if (pluginList == null) {
            return false;
         } else {
            for(String pluginName : pluginArray) {
               boolean exists = false;

               for(Plugin plugin : pluginList) {
                  if (plugin.getShortName().equals(pluginName)) {
                     exists = true;
                     break;
                  }
               }

               if (!exists) {
                  return false;
               }
            }

            return true;
         }
      }
   }

   public void upload() {
   }

   protected String[] getDependencyArray() {
      return null;
   }
}
